package cazsy.rj.PrototypePattern;
import java.util.ArrayList;
import java.util.List;

public class Plane implements Prototype{
    private String name;
    private String type;
    private List<String> passengers;//引用类型字段


    public Plane(){
        name = "Name:"+Math.random();
        type = "Type: "+Math.random();
        passengers = new ArrayList<>(); //初始化 passengers 列表
        passengers.add("Passenger 1"); //添加一个示例乘客
    }
    //深拷贝的构造方法
    public Plane(Plane plane) {
        this.name = plane.name;
        this.type = plane.type;
        this.passengers = new ArrayList<>(plane.passengers);
    }
    //浅拷贝的实现
    public Plane shallowClone() {
        Plane cloned = new Plane();
        cloned.name = this.name;
        cloned.type = this.type;
        cloned.passengers = this.passengers; // 浅拷贝：直接赋值引用
        return cloned; // 确保 return 在方法内部
    }
    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }
    public List<String> getPassengers() {
        return passengers;
    }

    @Override
    public Object clone() {
        return new Plane(this);
    }

}
